/*
 * @Author: xinqiao lxq1990.0716@qq.com
 * @Date: 2023-11-28 15:48:43
 * @LastEditors: xinqiao lxq1990.0716@qq.com
 * @LastEditTime: 2024-05-28 17:34:42
 * @FilePath: \h5-components-demo\vite.config.ts
 * @Description: 系统vite打包配置
 */
import { defineConfig, loadEnv } from 'vite'
import type { UserConfig, ConfigEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { fileURLToPath, URL } from 'node:url'
import topLevelAwait from 'vite-plugin-top-level-await'

// https://vitejs.dev/config/
export default ({ mode }: ConfigEnv): UserConfig => {
  const { VITE_BASE_ROUTE } = loadEnv(mode, process.cwd())

  return defineConfig({
    base: VITE_BASE_ROUTE,
    build: {

    },
    plugins: [
      vue(),
      vueJsx(),
      topLevelAwait({
        promiseExportName: '__tla',
        promiseImportName: i => `__tla${i}`
      })
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    server: {
      https: false,
      cors: true,
      host: '0.0.0.0',
      port: 4005,
      strictPort: false,
      hmr: true
    },
  })
}
